package com.wangyadong.hobby.common.utils;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import static java.util.stream.Collectors.joining;

/**
 * @ClassName ConfigurableApplition
 * @Description TODO
 * @Authpr Antonio
 * @Data 2018-07-09 14:55
 */
public class ConfigurableApplitionUtil {

    private static ConfigurableEnvironment environment = null;

    public static void set(ConfigurableApplicationContext run) {
//        environment = run.getEnvironment();
        UniqueIDUtil.init();
    }

    public static String getProperty(String str) {
        return environment.getProperty(str);
    }


    private static SqlSessionFactory sqlSessionFactory;

    public static SqlSessionFactory getSqlSessionFactory() {
        return sqlSessionFactory;
    }

    public static void setSqlSessionFactory(SqlSessionFactory sqlSessionDaoSupport) {
        ConfigurableApplitionUtil.sqlSessionFactory = sqlSessionDaoSupport;
    }

    public static void main(String[] args) {
        System.out.println(repalce("cne"));
    }

    public static String repalce(String userName) {
        String[] split = userName.split(",");
        userName = null;
        String user = "";
        for (int i = 0; i < split.length; i++) {
            user += "'" + split[i] + "'" + ",";
        }
        return user.substring(0, user.length() - 1);
    }
}
